home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / rhythmbox / plugins / magnatune / BuyAlbumHandler.py < prev    next >
Encoding:
Python Source  |  2009-04-07  |  2.3 KB  |  62 lines

  1. # -*- Mode: python; coding: utf-8; tab-width: 8; indent-tabs-mode: t; -*-
  2. #
  3. # Copyright (C) 2006 Adam Zimmerman  <adam_zimmerman@sfu.ca>
  4. # Copyright (C) 2006 James Livingston  <doclivingston@gmail.com>
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2, or (at your option)
  9. # any later version.
  10. #
  11. # The Rhythmbox authors hereby grant permission for non-GPL compatible
  12. # GStreamer plugins to be used and distributed together with GStreamer
  13. # and Rhythmbox. This permission is above and beyond the permissions granted
  14. # by the GPL license by which Rhythmbox is covered. If you modify this code
  15. # you may extend this exception to your version of the code, but you are not
  16. # obligated to do so. If you do not wish to do so, delete this exception
  17. # statement from your version.
  18. #
  19. # This program is distributed in the hope that it will be useful,
  20. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  22. # GNU General Public License for more details.
  23. #
  24. # You should have received a copy of the GNU General Public License
  25. # along with this program; if not, write to the Free Software
  26. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
  27.  
  28. import xml.sax, xml.sax.handler
  29.  
  30. class BuyAlbumHandler(xml.sax.handler.ContentHandler): # Class to download the track, etc.
  31.  
  32.     format_map =    {
  33.             'ogg'        :    'URL_OGGZIP',
  34.             'flac'        :    'URL_FLACZIP',
  35.             'wav'        :    'URL_WAVZIP',
  36.             'mp3-cbr'    :    'URL_128KMP3ZIP',
  37.             'mp3-vbr'    :    'URL_VBRZIP'
  38.             }
  39.  
  40.     def __init__(self, format):
  41.         xml.sax.handler.ContentHandler.__init__(self)
  42.         self._format_tag = self.format_map[format] # format of audio to download
  43.  
  44.     def startElement(self, name, attrs):
  45.         self._text = ""
  46.  
  47.     def endElement(self, name):
  48.         if name == "ERROR": # Something went wrong. Display error message to user.
  49.             raise MagnatunePurchaseError(self._text)
  50.         elif name == "DL_USERNAME":
  51.             self.username = self._text
  52.         elif name == "DL_PASSWORD":
  53.             self.password = self._text
  54.         elif name == self._format_tag:
  55.             self.url = self._text
  56.  
  57.     def characters(self, content):
  58.         self._text = self._text + content
  59.  
  60. class MagnatunePurchaseError(Exception):
  61.     pass
  62.